<?php
namespace app\index\controller;
use \think\Controller;
use \think\Db;
class Cate extends Controller
{
    public function index()
    {
    	
    	$data = Db::table('post')
    	->alias('p')
    	->join('user u','p.uid = u.uid')
    	->join('cate c','p.class_id = c.cid')
    	->field('post.*,cate.cname,user.avatar,user.username,user.level,user.is_approve')
    	->order('ctime desc')
        ->paginate(5);
    	// ->select();
        // $page = $data->render(); 
        var_dump($data);

        //本周热议
        $hotPost = Db::table('post')->field('pid,answer_num,title')->order('answer_num desc')->limit(10)->select();

        //回帖周榜
        $replyRank = Db::table('reply t1')
            ->field('t2.username,t2.avatar,t2.uid, count(t1.rid) cn')
            ->join('user t2','t1.uid=t2.uid')
            ->where('t1.ctime','>',strtotime('-7 days'))
            ->group('t1.uid')
            ->order('cn desc')
            ->limit(15)
            ->select();

        $cate = Db::table('cate')->select();

        return $this->fetch('',['replyRank'=>$replyRank,'data'=>$data,'hotPost'=>$hotPost,'cate'=>$cate]);
       
    }
  
}
